import { Byte } from '../../api/io/Byte';
import { HashMap } from '../../api/struct/HashMap';


export const enum E_CDLegionShop {
	/**货品编号*/
	id,
	/**物品类型--1-5道具表id(1.资源点2.道具3.装备4.符文5.魔纹)6.宠物99.dropSet*/
	itemType,
	/**购买道具ID*/
	itemId,
	/**购买道具数量*/
	itemNum,
	/**分组*/
	name,
	/**描述*/
	desc,
	/**军团等级限制*/
	legionLv,
	/**消耗道具ID*/
	costItemId,
	/**消耗道具数量*/
	costItemNum,

	/**枚举数量*/
	EnumCount
}



export class CDLegionShop{
	/**货品编号*/
	public id: number;
	/**物品类型--1-5道具表id(1.资源点2.道具3.装备4.符文5.魔纹)6.宠物99.dropSet*/
	public itemType: number;
	/**购买道具ID*/
	public itemId: number;
	/**购买道具数量*/
	public itemNum: number;
	/**分组*/
	public name: number;
	/**描述*/
	public desc: number;
	/**军团等级限制*/
	public legionLv: number;
	/**消耗道具ID*/
	public costItemId: number;
	/**消耗道具数量*/
	public costItemNum: number;


	/**获取属性值*/
	public getAttr(idx: number): any {
		switch(idx) { 
			default: return;
			case E_CDLegionShop.id: return this.id;
			case E_CDLegionShop.itemType: return this.itemType;
			case E_CDLegionShop.itemId: return this.itemId;
			case E_CDLegionShop.itemNum: return this.itemNum;
			case E_CDLegionShop.name: return this.name;
			case E_CDLegionShop.desc: return this.desc;
			case E_CDLegionShop.legionLv: return this.legionLv;
			case E_CDLegionShop.costItemId: return this.costItemId;
			case E_CDLegionShop.costItemNum: return this.costItemNum;
		}
	}



	/**设置属性值*/
	public setAttr(idx: number, v: any): void {
		switch(idx) { 
			default: break;
			case E_CDLegionShop.id: this.id = v; break;
			case E_CDLegionShop.itemType: this.itemType = v; break;
			case E_CDLegionShop.itemId: this.itemId = v; break;
			case E_CDLegionShop.itemNum: this.itemNum = v; break;
			case E_CDLegionShop.name: this.name = v; break;
			case E_CDLegionShop.desc: this.desc = v; break;
			case E_CDLegionShop.legionLv: this.legionLv = v; break;
			case E_CDLegionShop.costItemId: this.costItemId = v; break;
			case E_CDLegionShop.costItemNum: this.costItemNum = v; break;
		}
	}


	/**数据*/
	public static datas: HashMap<number, CDLegionShop> = new HashMap<number, CDLegionShop>();



	/**加载数据*/
	public static load(byte: Byte): void{
		const size = byte.readInt32();
		const list : CDLegionShop[] = [];
		let i :number;

		for (i = 0; i < size; i++) {
			list[i] = new CDLegionShop();
		}
		for (i = 0; i < size; i++) {
			list[i].id = byte.readInt32();
			this.datas.put(list[i].id, list[i]);
		}
		for (i = 0; i < size; i++) {
			list[i].itemType = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].itemId = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].itemNum = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].name = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].desc = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].legionLv = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].costItemId = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].costItemNum = byte.readInt32();
		}
	}


	/** 获取数据*/
	public static getData(id: number): CDLegionShop{
		return this.datas ? this.datas.get(id) : null;
	}
}
